<template>
  <el-dialog
    title="订单发货"
    :append-to-body="true"
    :visible.sync="deliveryVisible"
    width="30%"
    @open="open"
    :before-close="hidden"
  >
    <div style="with: 100%; text-align: center">
      <input type="file" ref="file" @change="getFile" />
      <p>注：模板下载：<a @click="tableModelDownload('Order/listDownload')">用户资料导入模板.xlsx</a></p>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="hidden">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import axios from "axios";
export default {
  props: {
    deliveryVisible: "",
    orderID: "",
    all: false,
  },
  data() {
    return {
      form: {},
      deliveryClass: [],
      file: "",
    };
  },
  methods: {

    open() {
      this.form.orderID = this.orderID;

    },
    tableModelDownload(api) {
      const elink = document.createElement("a");
      var urlHead =
          "http://collectapi.jujingame.com/%E7%94%A8%E6%88%B7%E8%B5%84%E6%96%99%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx";
      elink.style.display = "none";
      elink.href = urlHead;
      document.body.appendChild(elink);
      elink.click();
      URL.revokeObjectURL(elink.href); // 释放URL 对象
      document.body.removeChild(elink);
    },
    getFile() {
      let target = event.target.files;
      var name = target[0].name;
      var fileName = name.substring(name.lastIndexOf(".") + 1).toLowerCase();
      if (fileName != "xlsx" && fileName != "xls") {
        alert("请选择文件格式上传(只能后缀名为xls,xlsx的文件)！");
        this.$refs.file.value = "";
        return false; //阻止submit提交
      }
      this.file = event.target.files;
	  console.log(this.file)
    },
    onSubmit() {

      const formData = new FormData();
      formData.append("file", this.file[0]);
      axios({
        method: "post",
        url: "ClientUser/daoUser",
        data: formData,
      }).then((response) => {
        if (response.data.code === 1) {
          this.$message({
            message: response.data.msg,
            type: "success",
            offset: 100,
          });
          this.$refs.file.value = "";
          this.hidden();
        } else {
          this.$message({
            message: response.data.msg,
            type: "warning",
            offset: 100,
          });
        }
      });
    },

    hidden() {
      this.form = {};
      this.deliveryClass = [];
      this.$emit("hidden");
    },
  },
};
</script>

<style>
</style>
